<?php
/**
 * Joomla! 1.5 component Bbits Simple directory
 *
 * @version $Id: view.html.php 2011-07-08 03:53:16 svn $
 * @author Miguel Puig
 * @package Joomla
 * @subpackage Bbits Simple directory
 * @license GNU/GPL
 *
 * Simple Directory by bittingbits.com
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */
 
// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
class BbitsdViewItems extends JView {
    function display($tpl = null) {
	global $mainframe, $option;
		JToolBarHelper::title(JText::_('ITEMS'));
        JToolBarHelper::addNewX('addItem');
        JToolBarHelper::deleteList(JText::_('COM_BBSDIR_SURE'),'deleteItem');
        JToolBarHelper::editListX('editItem');
        
	
        
        $pagination =& $this->get('Pagination');
		
		$items =& $this->get('Data');
	
		$state = $this->get('State');


	$modelCountries = $this->getModel('countries');
	$modelTypes = $this->getModel('types');


$i=0;		
foreach($items as $item):

	if(isset($modelCountries->getCountryById($item->country)->title)):
		$items[$i]->country_data = $modelCountries->getCountryById($item->country);
	else:
		$items[$i]->country_data = '';
	endif;
	
	if(isset($modelTypes->getTypeById($item->type)->title)):
		$items[$i]->type_data = $modelTypes->getTypeById($item->type);
	else:
		$items[$i]->type_data = '';
	endif;

$i++;
endforeach;

        $this->assignRef('items', $items);
        $this->assignRef('pagination', $pagination);

	// prepare list array
   $lists = array();
	// get the user-state of the published filter  
   $filter_state = $mainframe->getUserStateFromRequest($option.'filter_state','filter_state');
    // set the table filter values
   $lists['state'] = JHTML::_('grid.state', $filter_state);

   // get the user state of the order and direction
   $filter_order = $mainframe->getUserStateFromRequest($option.'filter_order','filter_order', 'id');
   $filter_order_Dir = $mainframe->getUserStateFromRequest($option.'filter_order_Dir','filter_order_Dir', 'asc');
   
   $js = 'onchange="document.adminForm.submit();"';
   $filter_catid = $mainframe->getUserStateFromRequest($option.'filter_catid','filter_catid');
   $catlist[] = JHTML::_('select.option',  '0', JText::_( '- Select Country -' ), 'id', 'title' );
   $catlist = array_merge( $catlist, $modelCountries->getData() );
   $lists['catid'] = JHTML::_('select.genericlist', $catlist, 'filter_catid', 'class="inputbox" onchange="document.adminForm.submit();" size="1"','id', 'title', $filter_catid );  
   
   
   $filter_typeid = $mainframe->getUserStateFromRequest($option.'filter_typeid','filter_typeid');
   $typelist[] = JHTML::_('select.option',  '0', JText::_( '- Select Type of Business -' ), 'id', 'title' );
   $typelist = array_merge( $typelist, $modelTypes->getData() );
   $lists['typeid'] = JHTML::_('select.genericlist', $typelist, 'filter_typeid', 'class="inputbox" onchange="document.adminForm.submit();" size="1"','id', 'title', $filter_typeid );  


   // set the table order values
   $lists['order_Dir'] = $filter_order_Dir;
   $lists['order'] = $filter_order;
   
   // add the lists array to the object
   $this->assignRef('lists', $lists);
   

   $this->assignRef('catid', $filter_catid);
   $this->assignRef('typeid', $filter_typeid);

        parent::display($tpl);
        
    }
}
?>
